package com.retail.shop.controller;

import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;

import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.security.LoginUserUtil;
import com.retail.global.annon.TraceLog;
import com.retail.shop.entity.request.ShopCardRequest;
import com.retail.shop.entity.vo.ShopCardVo;
import com.retail.shop.service.ShopCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 权益卡项 API
* @author Administrator
*/
@Api(tags = "权益卡项 API")
@RestController
@RequestMapping("/shopCard")
public class ShopCardController extends AbstractCommonController<ShopCardService, ShopCardRequest, ShopCardVo>{

    @Autowired
    private ShopCardService shopCardService;

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(shopCardService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存权益卡项")
    public Result<Integer> save(@RequestBody ShopCardRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(shopCardService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新权益卡项")
    public Result<Integer> update(@RequestBody ShopCardRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(shopCardService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("权益卡项-查询")
    public Result<List<ShopCardVo>>listPage(@RequestBody ParamReq req) {
        return super.listPage(shopCardService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("权益卡项-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(shopCardService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("权益卡项-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<ShopCardRequest> req) {
        return super.page(shopCardService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除权益卡项")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(shopCardService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除权益卡项")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(shopCardService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
